<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>病人信息管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="../static/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../static/bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../static/bower_components/Ionicons/css/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="../static/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../static/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="../static/dist/css/skins/_all-skins.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="../static/bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap datepicker -->
    <link rel="stylesheet" href="../static/bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="../static/plugins/iCheck/all.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="../static/bower_components/select2/dist/css/select2.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../static/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="../static/dist/css/skins/_all-skins.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <header class="main-header">
        <!-- Logo -->
        <a href="#" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini">超</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg">超声波成像系统平台</span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>

            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">
                    <!--导航栏信息，已经删除-->
                </ul>
            </div>
        </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- Sidebar user panel -->
            <!-- search form -->
            <!-- /.search form -->
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul class="sidebar-menu" data-widget="tree">

                <li><a href="${pageContext.request.contextPath}/main/medicalRecords"><i class="fa fa-circle-o"></i>
                    病人病历管理</a></li>
                <li><a href="${pageContext.request.contextPath}/main/medicalRecordsAnalysis"><i
                        class="fa fa-circle-o"></i> 病人数据统计分析管理</a></li>
                <li><a href="${pageContext.request.contextPath}/main/imagingData"><i class="fa fa-circle-o"></i> 成像数据管理</a>
                </li>
                <li><a href="${pageContext.request.contextPath}/main/projectManage"><i class="fa fa-circle-o"></i> 项目管理</a>
                </li>
                <li><a href="${pageContext.request.contextPath}/main/commentManage"><i class="fa fa-circle-o"></i>
                    评价体系管理</a></li>
                <li><a href="${pageContext.request.contextPath}/main/logManage"><i class="fa fa-circle-o"></i> 平台日志信息管理</a>
                </li>
                <li><a href="${pageContext.request.contextPath}/main/consumableMaterial"><i class="fa fa-circle-o"></i>
                    平台耗材管理</a></li>
                <li><a href="${pageContext.request.contextPath}/main/userManage"><i class="fa fa-circle-o"></i>
                    平台用户及权限管理</a></li>
                <li><a href="${pageContext.request.contextPath}/main/platformPortal"><i class="fa fa-circle-o"></i>
                    超声波成像系统平台门户</a></li>
                <li><a href="${pageContext.request.contextPath}/main/sendControl"><i class="fa fa-circle-o"></i> 多通道发射控制</a>
                </li>
                <li><a href="${pageContext.request.contextPath}/main/receiveControl"><i class="fa fa-circle-o"></i>
                    多通道接收控制</a></li>
                <li><a href="${pageContext.request.contextPath}/main/syncControl"><i class="fa fa-circle-o"></i> 外部同步控制</a>
                </li>
                <li><a href="${pageContext.request.contextPath}/main/dataCollect"><i class="fa fa-circle-o"></i> 数据采集与重建</a>
                </li>
                <li><a href="${pageContext.request.contextPath}/main/waveGenerate"><i class="fa fa-circle-o"></i> 任意波束形成</a>
                </li>
                <li><a href="${pageContext.request.contextPath}/main/scriptManage"><i class="fa fa-circle-o"></i>
                    超声探头脚本管理</a></li>
                <li><a href="${pageContext.request.contextPath}/main/createImgAlgorithm"><i class="fa fa-circle-o"></i>
                    成像模式算法</a></li>
                <li><a href="${pageContext.request.contextPath}/main/resolveImgAlgorithm"><i class="fa fa-circle-o"></i>
                    图像处理算法</a></li>
                <li><a href="${pageContext.request.contextPath}/main/patientManage"><i class="fa fa-circle-o"></i>
                    病人信息管理</a></li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                病人信息管理
                <small>详细信息</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">病人信息管理</a></li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title"><b>病人信息管理表</b></h3>

                        </div>
                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover" id="mytable">
                                <tr>
                                    <th>记录序号</th>
                                    <th>姓名</th>
                                    <th>年龄</th>
                                    <th>电话号码</th>
                                    <th>操作</th>
                                </tr>
                                <tbody id="listTable">
                                </tbody>

                            </table>
                            <hr/>
                            <h3>新增数据</h3>
                            <form>
                                <table class="table table-hover table-bordered">
                                    <tr>
                                        <th>姓名</th>
                                        <td><input type="text" name="" class="form-control" id="TbName"/></td>
                                    </tr>
                                    <tr>
                                        <th>年龄</th>
                                        <td><input type="text" name="" class="form-control" id="TbAge"/></td>
                                    </tr>
                                    <tr>
                                        <th>电话号码</th>
                                        <td><input type="text" name="" class="form-control" id="TbPhone"/></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <input type="reset" value="重置" class="btn btn-primary" id="reset"/>
                                            <input type="button" value="添加" class="btn btn-success" id="add"
                                                   onclick="addList()"/>
                                            <input type="button" value="更新" class="btn btn-success" id=""
                                                   onclick="update()"/>
                                        </td>
                                    </tr>
                                </table>
                            </form>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 1.0.0
        </div>
        <strong>Copyright &copy; 2018 <a href="#">上海大学 </a>.</strong> All rights
        reserved.
    </footer>

    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Create the tabs -->
        <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
            <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
            <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
        </ul>
        <!-- Tab panes -->
        <div class="tab-content">
            <!-- Home tab content -->
            <div class="tab-pane" id="control-sidebar-home-tab">
                <h3 class="control-sidebar-heading">Recent Activity</h3>
                <ul class="control-sidebar-menu">
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-birthday-cake bg-red"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Langdon's Birthday</h4>

                                <p>Will be 23 on April 24th</p>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-user bg-yellow"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Frodo Updated His Profile</h4>

                                <p>New phone +1(800)555-1234</p>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-envelope-o bg-light-blue"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Nora Joined Mailing List</h4>

                                <p>nora@example.com</p>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-file-code-o bg-green"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Cron Job 254 Executed</h4>

                                <p>Execution time 5 seconds</p>
                            </div>
                        </a>
                    </li>
                </ul>
                <!-- /.control-sidebar-menu -->

                <h3 class="control-sidebar-heading">Tasks Progress</h3>
                <ul class="control-sidebar-menu">
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Custom Template Design
                                <span class="label label-danger pull-right">70%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-danger" style="width: 70%"></div>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Update Resume
                                <span class="label label-success pull-right">95%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-success" style="width: 95%"></div>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Laravel Integration
                                <span class="label label-warning pull-right">50%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-warning" style="width: 50%"></div>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Back End Framework
                                <span class="label label-primary pull-right">68%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-primary" style="width: 68%"></div>
                            </div>
                        </a>
                    </li>
                </ul>
                <!-- /.control-sidebar-menu -->

            </div>
            <!-- /.tab-pane -->
            <!-- Stats tab content -->
            <div class="tab-pane" id="control-sidebar-stats-tab">Stats Tab Content</div>
            <!-- /.tab-pane -->
            <!-- Settings tab content -->
            <div class="tab-pane" id="control-sidebar-settings-tab">
                <form method="post">
                    <h3 class="control-sidebar-heading">General Settings</h3>

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Report panel usage
                            <input type="checkbox" class="pull-right" checked>
                        </label>

                        <p>
                            Some information about this general settings option
                        </p>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Allow mail redirect
                            <input type="checkbox" class="pull-right" checked>
                        </label>

                        <p>
                            Other sets of options are available
                        </p>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Expose author name in posts
                            <input type="checkbox" class="pull-right" checked>
                        </label>

                        <p>
                            Allow the user to show his name in blog posts
                        </p>
                    </div>
                    <!-- /.form-group -->

                    <h3 class="control-sidebar-heading">Chat Settings</h3>

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Show me as online
                            <input type="checkbox" class="pull-right" checked>
                        </label>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Turn off notifications
                            <input type="checkbox" class="pull-right">
                        </label>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Delete chat history
                            <a href="javascript:void(0)" class="text-red pull-right"><i class="fa fa-trash-o"></i></a>
                        </label>
                    </div>
                    <!-- /.form-group -->
                </form>
            </div>
            <!-- /.tab-pane -->
        </div>
    </aside>
    <!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->
<script src="../static/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="../static/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../static/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="../static/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../static/bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../static/dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../static/dist/js/demo.js"></script>
<!-- page script -->
<!-- Select2 -->
<script src="../static/bower_components/select2/dist/js/select2.full.min.js"></script>
<!-- InputMask -->
<script src="../static/plugins/input-mask/jquery.inputmask.js"></script>
<script src="../static/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="../static/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<!-- date-range-picker -->
<script src="../static/bower_components/moment/min/moment.min.js"></script>
<script src="../static/bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- bootstrap datepicker -->
<script src="../static/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<!-- bootstrap color picker -->
<script src="../static/bower_components/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
<!-- bootstrap time picker -->
<script src="../static/plugins/timepicker/bootstrap-timepicker.min.js"></script>
<!-- iCheck 1.0.1 -->
<script src="../static/plugins/iCheck/icheck.min.js"></script>
<!-- ChartJS -->
<script src="../static/bower_components/chart.js/Chart.js"></script>

<!--echarts插件加载-->
<script src="../static/plugins/echarts/echarts.js"></script>
<script>
    $(document).ready(function () {
        //do something
        getData();
    })
</script>

<script>
    // 判断是否为手机号码
    function checkNum(input) {
        var re = /^[1-9]+[0-9]*]*$/;
        // var nubmer = document.getElementById(input).value;

        if (!re.test(input)) {
            alert("输入类型错误，请检查，确保为数字类型！");
            return false;
        }
        return true
    }
    function getData() {
        $.get("${pageContext.request.contextPath}/main/getPatientsInfo.do", function (data, status) {

            if (status === 'success') {
                var olistTable = document.getElementById('listTable');

                var json = JSON.parse(data);

                for (var i = 0; i < json.length; i++) {
                    var tr = document.createElement('tr');

                    var tdPrimaryKey = document.createElement('td');
                    tdPrimaryKey.innerHTML = json[i].id;

                    var tdName = document.createElement('td');
                    tdName.innerHTML = json[i].name;

                    var tdAge = document.createElement('td');
                    tdAge.innerHTML = json[i].age;

                    var tdPhone = document.createElement('td');
                    tdPhone.innerHTML = json[i].phone;

                    var tdCommand = document.createElement('td');
                    var inputDel = document.createElement('input');
                    inputDel.setAttribute('type', 'button');
                    inputDel.setAttribute('value', '删除');
                    inputDel.setAttribute('onclick', 'del(this)');
                    inputDel.className = 'btn btn-danger';

                    tdCommand.appendChild(inputDel);

                    var inputUpdate = document.createElement('input');
                    inputUpdate.setAttribute('type', 'button');
                    inputUpdate.setAttribute('value', '修改');
                    inputUpdate.setAttribute('onclick', 'modify(this)');
                    inputUpdate.className = 'btn btn-info';

                    tdCommand.appendChild(inputUpdate);


                    tr.appendChild(tdPrimaryKey);
                    tr.appendChild(tdName);
                    tr.appendChild(tdAge);
                    tr.appendChild(tdPhone);
                    tr.appendChild(tdCommand);

                    olistTable.appendChild(tr);
                }
            }

        });
    }

    // 删除功能
    //del单点功能
    function del(obj) {
        var oParentnode = obj.parentNode.parentNode;
        $.post("${pageContext.request.contextPath}/main/deletePatientsInfo.do", {
            id: oParentnode.cells[0].innerText.trim()
        }, function (result, status) {
            if (status === "success") {
                var olistTable = document.getElementById('listTable');
                olistTable.removeChild(oParentnode);
            }
            else {
                alert("删除记录失败！！！")
            }
        })
    }

    //add功能
    function addList() {

        var oTbName = document.getElementById('TbName').value;
        var oTbAge = document.getElementById('TbAge').value;
        var oTbPhone = document.getElementById('TbPhone').value;

        if(!checkNum(oTbAge)) {
            return;
        }
        if(!checkNum(oTbPhone)) {
            return;
        }
        $.post("${pageContext.request.contextPath}/main/addPatientsInfo.do", {
            od: -1,
            name: oTbName,
            age: oTbAge,
            phone: oTbPhone,
        }, function (result, status) {
            if (status === "success") {
                var oTr = document.createElement('tr');

                var oTd1 = document.createElement('td');
                oTd1.innerHTML = result.toString();

                var oTd2 = document.createElement('td');
                oTd2.innerHTML = oTbName;

                var oTd3 = document.createElement('td');
                oTd3.innerHTML = oTbAge;

                var oTd4 = document.createElement('td');
                oTd4.innerHTML = oTbPhone;


                var oTd5 = document.createElement('td');
                var oInput2 = document.createElement('input');
                oInput2.setAttribute('type', 'button');
                oInput2.setAttribute('value', '删除');
                oInput2.setAttribute('onclick', 'del(this)');
                oInput2.className = 'btn btn-danger';

                oTd5.appendChild(oInput2);

                var inputUpdate = document.createElement('input');
                inputUpdate.setAttribute('type', 'button');
                inputUpdate.setAttribute('value', '修改');
                inputUpdate.setAttribute('onclick', 'modify(this)');
                inputUpdate.className = 'btn btn-info';

                oTd5.appendChild(inputUpdate);


                oTr.appendChild(oTd1);
                oTr.appendChild(oTd2);
                oTr.appendChild(oTd3);
                oTr.appendChild(oTd4);
                oTr.appendChild(oTd5);


                var olistTable = document.getElementById('listTable');
                olistTable.appendChild(oTr);
            }
            else {
                alert("添加记录失败！！！")
            }
        })

    }

    // modify功能
    function modify(obj) {
        var oTbName = document.getElementById('TbName');
        var oTbAge = document.getElementById('TbAge');
        var oTbPhone = document.getElementById('TbPhone');

        var oTr = obj.parentNode.parentNode;
        var aTd = oTr.getElementsByTagName('td');
        rowIndex = obj.parentNode.parentNode.rowIndex;
        oTbName.value = aTd[1].innerHTML;
        oTbAge.value = aTd[2].innerHTML;
        oTbPhone.value = aTd[3].innerHTML;


    }

    // Todo update 功能
    function update() {
        var oTbName = document.getElementById('TbName').value;
        var oTbAge = document.getElementById('TbAge').value;
        var oTbPhone = document.getElementById('TbPhone').value;
        if(!checkNum(oTbAge)) {
            return;
        }
        if(!checkNum(oTbPhone)) {
            return;
        }

        var oMytable = document.getElementById('mytable');
        //alert(rowIndex);
        //var aTd = rowIndex.cells;
        console.log(oMytable.rows[rowIndex].cells);

        $.post("${pageContext.request.contextPath}/main/addPatientsInfo.do", {
            id: oMytable.rows[rowIndex].cells[0].innerHTML,
            name: oTbName,
            age: oTbAge,
            phone: oTbPhone,
        }, function (result, status) {
            if (status === "success") {
                oMytable.rows[rowIndex].cells[1].innerHTML = oTbName;
                oMytable.rows[rowIndex].cells[2].innerHTML = oTbAge;
                oMytable.rows[rowIndex].cells[3].innerHTML = oTbPhone;
            }
            else {
                alert("添加记录失败！！！")
            }
        })


    }
</script>
</body>
</html>
